{template '_header'}
<style type="text/css">
    .table_kf {display: none;}
    .table_kf.active {display: table-footer-group;}
</style>
<div class="page-heading">
    <span class='pull-right'>
        {ifp 'sale.goodscode.add'}
            <a class='btn btn-primary btn-sm' href="{php echo webUrl('sale/goodscode/add')}"><i class='fa fa-plus'></i> 添加商品</a>
        {/if}
    </span>
    <h2>商品二维码管理</h2> </div>

<form action="./index.php" method="get" class="form-horizontal form-search" role="form">
    <input type='hidden' id='tab' name='type' value="{$_GPC['type']}"/>
    <input type="hidden" name="c" value="site" />
    <input type="hidden" name="a" value="entry" />
    <input type="hidden" name="m" value="mx_shop" />
    <input type="hidden" name="do" value="web" />
    <input type="hidden" name="r"  value="sale.goodscode" />

    <div class="page-toolbar row m-b-sm m-t-sm">
        <div class="col-sm-6">

            <div class="input-group-btn">
                <button class="btn btn-default btn-sm"  type="button" data-toggle='refresh'><i class='fa fa-refresh'></i></button>
                {ifp 'sale.goodscode.delete1'}
                <button class="btn btn-default btn-sm" type="button" data-toggle='batch-remove' data-confirm="确认要彻底删除吗?" data-href="{php echo webUrl('sale/goodscode/delete1')}">
                    <i class='fa fa-remove'></i> 彻底删除
                </button>
                {/if}
                {ifp 'sale.goodscode.download'}
                <a  class='btn btn-default btn-sm' id="download" target="_blank"  href="javascript:void(0);">
                    <i class='fa fa-download'></i> 批量下载
                </a>
                {/if}
            </div>
        </div>
        <div class="col-sm-6 pull-right">
            <div class="input-group">
                <input type="text" class="input-sm form-control" name='keyword' value="{$_GPC['keyword']}" placeholder="商品名称"> <span class="input-group-btn">
                <button class="btn btn-sm btn-primary" type="submit"> 搜索</button> </span>
            </div>
        </div>
    </div>
</form>
<form action="" method="post">
    <table class="table table-hover table-responsive">
        <thead class="navbar-inner">
        <tr>
            <th style="width:25px;"><input type='checkbox' /></th>
            <th style="width:60px;text-align:center;">排序</th>
            <th style="width:80px;">商品名称</th>
            <th  style="">&nbsp;</th>
            <th  style="width:60px;" >状态</th>
            <th style="width:400px;text-align: center;">操作</th>
        </tr>
        </thead>
        <tbody class=" table_kf active" id="tab_all">
        {if count($goodscodes)>0}
        {loop $goodscodes $item}
        <tr>
            <td>
                <input type='checkbox'  value="{$item['id']}"/>
            </td>
            <td style='text-align:center;'>
                {ifp 'sale.goodscode.edit'}
                <a href='javascript:;' data-toggle='ajaxEdit' data-href="{php echo webUrl('sale/goodscode/change',array('typechange'=>'displayorder','id'=>$item['id']))}" >{$item['displayorder']}</a>
                {else}
                {$item['displayorder']}
                {/if}
            </td>
            <td>
                <img src="{php echo tomedia($item['thumb'])}" style="width:40px;height:40px;padding:1px;border:1px solid #ccc;"  />
            </td>
            <td class='full' style="overflow-x: hidden">
                {$item['title']}
            </td>
            <td  style="overflow:visible;">
                <span class='label {if $item['status']==1}label-success{else}label-default{/if}'
                {ifp 'sale.goodscode.edit'}
                data-toggle='ajaxSwitch'
                data-confirm = "确认是{if $item['status']==1}关闭{else}开启{/if}？"
                data-switch-refresh='true'
                data-switch-value='{$item['status']}'
                data-switch-value0='0|关闭|label label-default|{php echo webUrl('sale/goodscode/status',array('status'=>1,'id'=>$item['id']))}'
                data-switch-value1='1|开启|label label-success|{php echo webUrl('sale/goodscode/status',array('status'=>0,'id'=>$item['id']))}'
                {/if}>
                {if $item['status']==1}开启{else}关闭{/if}</span>
            </td>
            <td  style="overflow:visible;position:relative;text-align: right;">
                {ifp 'sale.goodscode.edit|sale.goodscode.view'}
                <a  class='btn btn-default btn-sm' href="{php echo webUrl('sale/goodscode/edit', array('type'=>$_GPC['type'],'id' => $item['id'],'page'=>$page))}" title="{ifp 'sale.goodscode.edit'}编辑{else}查看{/if}">
                    <i class='fa fa-edit'></i> {ifp 'sale.goodscode.edit'}编辑{else}查看{/if}
                </a>
                {/if}
                <a href="javascript:void(0);" class="btn btn-default btn-sm" data-toggle="popover" data-trigger="hover" data-html="true"
                   data-content="<img src='{$item['qrcode']}' width='130' alt='二维码预览'>" data-placement="auto right">
                    <i class="glyphicon glyphicon-qrcode"></i>
                </a>
                {ifp 'sale.goodscode.download'}
                <a  class='btn btn-default btn-sm' target="_blank" href="{php echo webUrl('sale/goodscode/download', array('id' => $item['id']))}"><i class='fa fa-download'></i> 下载</a>
                {/if}
                {ifp 'sale.goodscode.delete1'}
                <a  class='btn btn-default btn-sm' data-toggle='ajaxRemove' href="{php echo webUrl('sale/goodscode/delete1', array('id' => $item['id']))}" data-confirm='如果此活动存在购买记录，会无法关联到商品, 确认要彻底删除吗?？'><i class='fa fa-remove'></i> 彻底删除</a>
                {/if}
            </td>
        </tr>
        <tr>
            <td colspan='3' style='text-align: left;border-top:none;padding:5px 0;' class='aops'>
                {if !empty($item['merchname']) && $item['merchid'] > 0}
                <span class="text-default" style="margin-left: 95px;">商户名称:</span><span class="text-info">{$item['merchname']}</span>
                {/if}
            </td>

            <td colspan='3' style='text-align: right;border-top:none;padding:5px 0;' class='aops'></td>
        </tr>
        {/loop}
        {else}
        <td colspan="6" style="text-align: center;">暂时没有任何记录!</td>
        {/if}
        </tbody>
    </table>
</form>
<div style="text-align:right;width:100%;">
    {$pager}
</div>
<script type="text/javascript">
    $(function () {
        var href = "{php echo webUrl('sale/goodscode/download')}";
        $("#download").off('click').on('click',function () {
            var ids = [];
            $("input[type='checkbox']:checked").each(function (index,event) {
                if(parseInt($(this).val())>0){
                    ids.push(parseInt($(this).val()));
                }
            });
            if(ids.length==0){
                return false;
            }
            href += "&ids="+ids;
            $("#download").attr('href',href);
        });
    })
</script>
{template '_footer'}
